/**
 * Created by issuser on 2016/9/9.
 */
'use strict';

app.controller('PersonalCtrl',
    ['$scope', 'dialogs', '$state', 'PersonalService',
        function ($scope, dialogs, $state, PersonalService) {
            var vm = $scope.vm = this;
            vm.active = 0;
            var isFirstLogin = false;
            var userId = angular.copy($scope.app.loginUser.id);
            if (!ISS.isEmpty(userId)) {
                PersonalService.initUpdate(userId).then(function (data) {
                    if (data.success === false) {
                        dialogs.notify(data);
                    } else {
                        vm.user = data;
                        if (vm.user.resetPwd == 1) {
                            vm.active = 2;
                            isFirstLogin = true;
                        }
                        delete vm.user.createTime;
                        // delete vm.user.fax;
                        delete vm.user.archs;
                    }
                });
            }
            ;

            /*        vm.insert  = function () {
             if (!$('#form-insert').valid()) return;
             var iconZone = Dropzone.get('icon'); // icon图片空间
             if (!(iconZone && iconZone.valid())) return;
             var iconData = iconZone.getFileData(0);
             $scope.inputs.icon = iconData && iconData.fileFileName;
             $JSON.$httpGet($http, $scope, {
             url: $scope.isUpdate ? 'travel/update.action' : 'travel/insert.action',
             data: $scope.inputs,
             success: function (object, array) {
             $rootScope.modalConfirm = function () {
             $location.url('/travel-list');
             $('#modal-root-normal').modal('hide');
             };
             modal.show('#modal-root-normal', {
             title: '成功',
             content: ($scope.isUpdate ? '更新' : '添加') + '成功',
             cancel: '继续添加',
             confirm: '查看列表'
             });
             }
             });
             };*/

            vm.saveUser = function () {
                PersonalService.updateCurrUser(vm.user).then(function (data) {
                    dialogs.notify(data);
                });
            };

            vm.savePassword = function () {
                PersonalService.updatePassword(vm.user).then(function (data) {
                    if (data.success === false) {
                        dialogs.notify(data);
                    } else {
                        dialogs.notify(data);
                        /*if(isFirstLogin){
                         $state.go('app.block');
                         }*/
                    }
                });
            };
        }]);